package org.jingle.sketch
{
	import flash.events.MouseEvent;
	
	import org.jingle.sketch.component.Composite;
	import org.jingle.sketch.component.Point;
	import org.jingle.sketch.component.Rectangle;
	import org.jingle.sketch.event.MagneticEvent;
	
	public class Wall extends Composite
	{
		private var _width:int;
		
		private var _length:int;
		
		private var stickArea:Rectangle;
		
		private var wall:Rectangle;
		
		private var wallThickness:int = 10;
		
		public function Wall(parent:Composite, start:Point, length:int, width:int = 10) {
			super(parent);
			this.origin = start;
			this._length = length;
			this._width = width;
			this.dragEnable(true);
		}
		
		public override function init():void {
			if(stickArea){
				this.removeChild(stickArea);
			}
			if(wall){
				this.removeChild(wall);
			}
			stickArea = new Rectangle(this, new Point(origin.x, origin.y - wallThickness / 2), length, width + wallThickness);
			stickArea.alpha = 0.4;
			stickArea.paint();
			stickArea.addEventListener(MouseEvent.MOUSE_OVER, magnetic);
			
			
			wall = new Rectangle(this, origin, length, width);
			wall.fillColor = 0xAB8EE0;
			wall.alpha = 0.5;
			wall.paint();
			
			function magnetic():void {
				var evt:MagneticEvent = new MagneticEvent(MagneticEvent.ON_CLOSE);
				wall.sprite.dispatchEvent(evt);
			}
		}
		
		public function set width(w:int):void {
			this._width = w;
		}
		
		public function  get width():int {
			return this._width;
		}
		
		public function set length(l:int):void {
			this._length = l;
		}
		
		public function  get length():int {
			return this._length;
		}
	}
}